package cn.silver.module.quartz.enums;

import cn.silver.framework.core.model.DictModel;
import cn.silver.framework.core.utils.StreamUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;

/**
 * @author zhouxiaobo
 */

@Getter
@AllArgsConstructor
public enum QuartzStrategyEnums {

    STRATEGY_DEAFUAL("00", "默认策略"),
    STRATEGY_IMMEDIATE("01", "立即执行"),
    STRATEGY_ONCE("02", "执行一次"),
    STRATEGY_ABANDON("03", "放弃执行"),
    ;
    private final String code;
    private final String name;

    public static QuartzStrategyEnums getStrategy(String code) {
        return Arrays.stream(values()).filter(t -> t.getCode().equals(code)).findFirst().orElse(QuartzStrategyEnums.STRATEGY_DEAFUAL);
    }

    public static List<DictModel> getModels() {
        return StreamUtils.toList(Arrays.asList(values()), item -> new DictModel(item.name, item.code));
    }
}
